package mall

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

/**
 * @Author: zhaobin
 * @Description TODO
 * @Date: 2022-04-25 21:08
 */

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

// ResponseError 响应失败
func ResponseError(c *gin.Context, message string) {
	re := &Response{
		Code:    400,
		Message: message,
		Data:    nil,
	}
	c.JSON(http.StatusOK, re)
}

// ResponseErrorWithData 带数据的响应失败
func ResponseErrorWithData(c *gin.Context, message string, data interface{}) {
	re := &Response{
		Code:    400,
		Message: message,
		Data:    data,
	}
	c.JSON(http.StatusOK, re)
}

// ResponseSuccess 响应成功
func ResponseSuccess(c *gin.Context, data interface{}) {
	re := &Response{
		Code:    http.StatusOK,
		Message: "success",
		Data:    data,
	}
	c.JSON(http.StatusOK, re)
}

// ResponseSuccessWithMessage 响应成功
func ResponseSuccessWithMessage(c *gin.Context, message string, data interface{}) {
	re := &Response{
		Code:    http.StatusOK,
		Message: message,
		Data:    data,
	}
	c.JSON(http.StatusOK, re)
}
